package com.study.runnable;


import sun.applet.Main;
import sun.security.krb5.internal.Ticket;

/*
* 多个线程访问通一个资源问题
* */
public class RunnableTest implements Runnable{
    // 票数
    private int ticket = 100;
    public void run() {
      while (true){
          if (ticket <=0)
              break;
          // 模拟延迟
          try {
              Thread.sleep(200);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
          System.out.println(Thread.currentThread().getName()+"----->拿到第:"+ticket--+"张票");
      }
    }

    public static void main(String[] args) {
        RunnableTest test = new RunnableTest();
        new Thread(test,"小明").start();
        new Thread(test,"小红").start();
        new Thread(test,"小黄").start();
    }
}
